package org.game.gobang.server.init;

import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import io.netty.handler.timeout.IdleStateHandler;
import org.game.codec.MsgpackDecoder;
import org.game.codec.MsgpackEncoder;
import org.game.gobang.server.handler.CustomizeServerHandler;
import org.game.gobang.server.handler.GobangServerHandler;

import java.util.concurrent.TimeUnit;

public class GobangServerInitializer extends ChannelInitializer<Channel> {
    @Override
    protected void initChannel(Channel channel) throws Exception {
        ChannelPipeline pipeline = channel.pipeline();
        pipeline.addLast("decoder", new MsgpackDecoder());
        pipeline.addLast("encoder", new MsgpackEncoder());
        pipeline.addLast(new LoggingHandler(LogLevel.INFO));
//        pipeline.addLast(new IdleStateHandler(5,2,2, TimeUnit.SECONDS));
        pipeline.addLast(new CustomizeServerHandler());
    }
}